var express = require('express');
var router = express.Router();
var Post = require('../models/posts.js');


router.get('/',function(req,res,next){
    if(req.query.edit){
        Post.getAllToEdit(function(err,posts){
            if(err){
                res.json({"success":false,message:'获取文章失败',posts:[]});
            }else{
                res.json({"success":true,message:'获取文章成功',posts:posts});
            }
        })
    }else{
        Post.getAll(function(err,posts){
            if(err){
                res.json({"success":false,message:'获取文章失败',posts:[]});

            }else{
                res.json({"success":true,message:'获取文章成功',posts:posts});
            }
        })
    }

});

module.exports = router;